#!/bin/sh
set -o nounset
#set -x #DEBUG

cd $SCRIPT_BINDDIR
. bin/rootfs-library.sh

# Only need a new initramfs if using encrypted rootfs
exit_if_not_configured CONFIG_ENCRYPT_ROOTFS
exit_if_stamped $0

refresh_or_install_file \
    /etc/initramfs-tools/initramfs.conf \
    "Installing custom initrd configuration..."

printinfo "Patching init scripts for encrypted rootfs..."
patch -d / -p1 < patches/rootfs/casper-encsqfs.diff || die "Unable to patch initramfs-tools casper script!"

# Create new initramfs that includes cryptsetup
printinfo Creating new initramfs with crypto hooks...
export CRYPTSETUP=y
update-initramfs -k all -u || die "Unable to execute update-initramfs!"

updated_rootfs
make_stamp $0

exit 0
